package com.tougutips.config;

import com.tougutips.common.core.constant.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 秒杀活动通知队列
 */
@Configuration
public class PublishSeckillMsgConfig {

    /**
     * 创建通知队列
     *
     * @return
     */
    @Bean
    public Queue noticeQueue() {
        return new Queue(MqConstants.NOTICE_QUEUE);
    }

    /**
     * 创建广播交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(MqConstants.EXCHANGE_FANOUT);
    }

    @Bean
    public Binding binding() {
        //绑定队列和广播交换机
        return BindingBuilder.bind(noticeQueue()).to(fanoutExchange());
    }

}
